package net.irisshaders.iris.compat.sodium.mixin;

import com.google.common.collect.ImmutableList;
import net.caffeinemc.mods.sodium.client.gui.SodiumOptionsGUI;
import net.caffeinemc.mods.sodium.client.gui.options.OptionPage;
import net.irisshaders.iris.gui.screen.ShaderPackScreen;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import java.util.List;

@Mixin(SodiumOptionsGUI.class)
public class MixinSodiumOptionsGUI extends Screen {
	@Shadow(remap = false)
	@Final
	private List<OptionPage> pages;

	@Unique
	private OptionPage shaderPacks;

	// make compiler happy
	protected MixinSodiumOptionsGUI(Component title) {
		super(title);
	}

	@Inject(method = "<init>", at = @At("RETURN"))
	private void iris$onInit(Screen prevScreen, CallbackInfo ci) {
		Component shaderPacksTranslated = Component.translatable("options.iris.shaderPackSelection");
		shaderPacks = new OptionPage(shaderPacksTranslated, ImmutableList.of());
		pages.add(shaderPacks);
	}

	@Inject(method = "setPage", at = @At("HEAD"), remap = false, cancellable = true)
	private void iris$onSetPage(OptionPage page, CallbackInfo ci) {
		if (page == shaderPacks) {
			minecraft.setScreen(new ShaderPackScreen(this));
			ci.cancel();
		}
	}
}
